≡ Menu

4 Steps to Define Nagios Contacts With Email and Pager Notification

Nagios Contact and Group ManagementNagios is one of the best open source server and network monitoring solutions available.  Using the flexible nagios framework, you can monitor pretty much anything (including database and custom application). This article, using 4 simple steps, explains how to setup contact definitions who will get notification when a host or service has any issues.
 
Earlier we also discussed about how to setup Nagios and monitor Windows server, monitor Linux Server, monitor VPN sessions and monitor network switch.

1. Define Generic Contact Template in templates.cfg

Nagios installation gives a default generic contact template that can be used as a reference to build your contacts. Please note that all the directives mentioned in the generic-contact template below are mandatory. So, if you’ve decided not to use the generic-contact template definition in your contacts, you should define all these mandatory definitions inside your contacts yourself.
 
The following generic-contact is already available under /usr/local/nagios/etc/objects/templates.cfg. Also, the templates.cfg is included in the nagios.cfg by default as shown below.
 
Please note that any of these directives mentioned in the templates.cfg can be overridden when you define a real contact using this generic-template.

# grep templates /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

Note: generic-contact is available under
      /usr/local/nagios/etc/objects/templates.cfg

define contact{
        name                            generic-contact
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r,f,s
        host_notification_options       d,u,r,f,s
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        register                        0
        }

 

  • Name – This defines the name of the contact template (generic-contact).
  • service_notification_period – This defines when nagios can send notification about services issues (for example, Apache down). By default this is 24×7 timeperiod, which is defined under /usr/local/nagios/etc/objects/timeperiods.cfg
  • host_notification_period – This defines when nagios can send notification about host issues (for example, server crashed). By default, this is 24×7 timeperiod.
  • service_notification_options – This defines the type of service notification that can be sent out. By default this defines all possible service states including flapping events. This also includes the scheduled service downtime activities.
  • host_notification_options – This defines the type of host notifications that can be sent out. By default this defines all possible host states including flapping events. This also includes the scheduled host downtime activities.
  • service_notification_commands – By default this defines that the contact should get notification about service issues (for example, database down) via email. You can also define additional commands and add it to this directive. For example, you can define your own notify-service-by-sms command.
  • host_notification_commands – By default this defines that the contact should get notification about host issues (for example, host down) via email. You can also define additional commands and add it to this directive. For example, you can define your own notify-host-by-sms command.

2. Define Individual Contacts in contacts.cfg

One you’ve confirmed that the generic-contact templates is defined properly, you can start defining individual contacts definition for all the people in your organization who would ever receive any notifications from nagios. Please note that just by defining a contact doesn’t mean that they’ll get notification. Later you have to associate this contact to either a service or host definition as shown in the later sections below. So, feel free to define all possible contacts here. (for example, Developers, DBAs, Sysadmins, IT-Manager, Customer Service Manager, Top Management etc.)
 

Note: Define these contacts in /usr/local/nagios/etc/objects/contacts.cfg
define contact{
        contact_name                    sgupta
        use                             generic-contact
        alias                           Sanjay Gupta (Developer)
        email                           sgupta@thegeekstuff.com
        pager                           333-333@pager.thegeekstuff.com
        }
define contact{
        contact_name                    jbourne
        use                             generic-contact
        alias                           Jason Bourne (Sysadmin)
        email                           jbourne@thegeekstuff.com
        }

3. Define Contact Groups with Multiple Contacts in contacts.cfg

Once you’ve defined the individual contacts, you can also group them together to send the appropriate notifications. For example, only DBAs needs to be notified about the database down service definition. So, a db-admins group may be required. Also, may be only Unix system administrators needs to be notified when Apache goes down. So, a unix-admins group may be required. Feel free to define as many groups as you think is required. Later you can use these groups in the individual service and host definitions.
 

Note: Define contact groups in /usr/local/nagios/etc/objects/contacts.cfg

define contactgroup{
contactgroup_name          db-admins
alias                      Database Administrators
members                    jsmith, jdoe, mraj
}

define contactgroup{
contactgroup_name          unix-admins
alias                      Linux System Administrator
members                    jbourne, dpatel, mshankar
}

4. Attach Contact Groups or Individual Contacts to Service and Host Definitions

Once you’ve defined the individual contacts and contact groups, it is time to start attaching them to a specific host or service definition as shown below.
 

Note: Following host is defined under
     /usr/local/nagios/etc/objects/servers/email-server.cfg.
     This can be any host definition file.

define host{
use                     linux-server
host_name               email-server
alias                   Corporate Email Server
address                 192.168.1.14
contact_groups          unix-admins
}

Note: Following is defined under
      /usr/local/nagios/etc/objects/servers/db-server.cfg.
      This can be any host definition file.

define service{
use                             generic-service
host_name                       prod-db
service_description             CPU Load
contact_groups                  unix-admins
check_command                   check_nrpe!check_load
}

define service{
use                             generic-service
host_name                       prod-db
service_description             MySQL Database Status
contact_groups                  db-admins
check_command                   check_mysql_db
}
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Krushna March 10, 2011, 8:53 am

    Thanks for sharing

  • Reynold August 26, 2011, 12:35 pm

    Thank you:)

  • Ellis April 5, 2012, 2:36 am

    Thanks! That’s a useful reference. Short and sweet.

  • Vivek April 11, 2012, 10:58 pm

    Thnx!!! Crisp & clear..!!

  • paddy April 18, 2012, 6:04 am

    Thanks ! ! !

  • kishan May 9, 2012, 12:13 am

    good article!! keep it up

  • Minh Duc July 1, 2012, 10:01 pm

    Very practical and easy to understand, thanks so much.

  • bayzid September 5, 2012, 6:30 am

    I setup everything like your column but fails when run
    #nagios -v /usr/local/nagios/etc/nagios.cfg

    and found the below error.
    Error: Invalid hostgroup object directive ‘contact_groups’.

    I gooled a few and found ‘contact_groups’ is not supported by nagios core 3. But I need that service in order to ensure user based access restriction on the web frontend. Please suggest me what I do now?

    Thanks in advance.

  • 519seven June 13, 2013, 9:57 am

    Thanks for this guide. Very easy to follow. The only part that had me confused was the step “Define Generic Contact Template in templates.cfg”. Basically, to use the generic-contact that is already listed there, the only thing that is needed is to give “register” a value of “1”, right?

  • Pradeep August 1, 2013, 11:58 pm

    Thanks for the cool article 🙂

  • Jagan October 29, 2013, 1:06 am

    Hi Team,

    i have configured nagios and working fine..i have some alerts which disturb other folks also so i want to send those alerts to only defined group.. i tried above procedure but alert mails sent all of the team.but didn’t go to defined group..How to send those specific alerts to specified emails. Please help me..Thanks in Advance..

    Thanks
    Jagan M

  • amit December 3, 2013, 2:48 am

    Hi,
    I am able to send email by the command prompt but unable to send by command.cfg 🙁
    Please help me.

  • Siddesh January 7, 2014, 6:30 am

    Hi Guys,

    I have configured as above, and am testing for gmail/yahoo but nothing is working.

    Do i need to define or change settings..?

    please confirm update me on this.

    Thanks,
    Siddesh SV

  • Bryan March 4, 2014, 9:48 am

    Hi All,

    Please give me an advice, I’m having an issue to defining the:

    /usr/local/nagios/etc/objects/servers/email-server.cfg.

    I couldn’t find this .cfg file? Is it possible just to create a directory and email-server.cfg. You think, it would work?

    Thank you in advance.

    Bryan

  • John June 3, 2014, 11:42 am

    Hello,

    How do I get Nagios to do Disk free in Linux instead of usage.

    Thanks

  • manik October 4, 2014, 11:01 am

    Thanks, its Good article

  • Svenson November 11, 2014, 4:00 am

    Good one, thank you!

  • jhon January 28, 2016, 1:49 pm

    Can I send notification at some port rather email, in Nagios? If yes then how?